using JRO;
using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.IO;
public class SendUtil
{
	public OleDbCommand oleDbCommand_0;
	private OleDbCommand oleDbCommand_1;
	private OleDbCommand oleDbCommand_2;
	public OleDbCommand oleDbCommand_3;
	private OleDbCommand oleDbCommand_4;
	public OleDbCommand oleDbCommand_5;
	private OleDbCommand oleDbCommand_6;
	public OleDbCommand oleDbCommand_7;
	private OleDbCommand oleDbCommand_8;
	private OleDbConnection oleDbConnection_0;
	private string app_path;
	public SendUtil()
	{
		this.app_path = Directory.GetCurrentDirectory();
		this.oleDbCommand_0 = null;
		this.oleDbCommand_1 = null;
		this.oleDbCommand_2 = null;
		this.oleDbCommand_4 = null;
		this.set_pay_order_mdb();
	}
	public SendUtil(string string_1)
	{
		this.app_path = Directory.GetCurrentDirectory();
		this.oleDbCommand_0 = null;
		this.oleDbCommand_1 = null;
		this.oleDbCommand_2 = null;
		this.oleDbCommand_4 = null;
		this.method_1(string_1);
	}
	public void set_pay_order_mdb()
	{
		this.method_1(this.app_path + "\\config\\阿里妈妈订单.mdb");
	}
	public void method_1(string string_1)
	{
		if (this.oleDbConnection_0 == null)
		{
			string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + string_1 + ";Jet OLEDB:Database Password=ali(*)135";
			this.oleDbConnection_0 = new OleDbConnection(connectionString);
			this.oleDbConnection_0.Open();
		}
	}
	public bool delete_send_task(out string string_1)
	{
		string string_2 = "delete from sendtask ";
		return this.method_7(string_2, out string_1);
	}
	public bool method_11(SendTaskItem gclass11_0, out string string_1)
	{
		string text = "delete from sendtask  where taskid={taskid}";
		text = text.Replace("{taskid}", string.Concat(gclass11_0.task_id));
		return this.method_7(text, out string_1);
	}
	public ArrayList method_12(string string_1, out string string_2)
	{
		ArrayList result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			ArrayList arrayList = new ArrayList();
			if (this.oleDbCommand_4 == null || this.oleDbCommand_4.Connection == null || this.oleDbCommand_4.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_4 = new OleDbCommand(string_1, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_4.CommandText = string_1;
			}
			OleDbDataReader oleDbDataReader = this.oleDbCommand_4.ExecuteReader();
			while (oleDbDataReader.Read())
			{
				SendTaskItem sendTaskItem = new SendTaskItem();
				sendTaskItem.task_id = int.Parse(oleDbDataReader["taskid"].ToString());
				string text = oleDbDataReader["taskdt"].ToString();
				sendTaskItem.task_time = DateTime.Now.ToString("yyyy") + ((text.Length != 10) ? ("0" + text) : text);
				sendTaskItem.task_name = oleDbDataReader["taskname"].ToString();
				arrayList.Add(sendTaskItem);
			}
			oleDbDataReader.Close();
			oleDbDataReader.Dispose();
			string_2 = "";
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = ex.ToString();
			result = null;
		}
		return result;
	}
	public bool create_campaign(string shopkeeperid, string user_num_id, string campaign_id, out string out_log)
	{
		bool result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			this.method_20(out out_log);
			string text = "INSERT INTO campaign(shopkeeperid, usernumberid, campaignid) VALUES ('{shopkeeperid}','{usernumberid}','{campaignid}');";
			text = text.Replace("{shopkeeperid}", shopkeeperid).Replace("{usernumberid}", user_num_id).Replace("{campaignid}", campaign_id);
			if (this.oleDbCommand_5 == null || this.oleDbCommand_5.Connection == null || this.oleDbCommand_5.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_5 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_5.CommandText = text;
			}
			this.oleDbCommand_5.ExecuteNonQuery();
			out_log = "";
			result = true;
		}
		catch (Exception ex)
		{
			out_log = "出错啦！" + ex.ToString();
			this.method_23();
			result = false;
		}
		return result;
	}
	public CampaignBean method_14(string shopkeeperid, string user_num_id, string campaign_id, out string out_log)
	{
		string string_ = string.Concat(new string[]
		{
			"select * from campaign where shopkeeperid='",
			shopkeeperid,
			"' and  usernumberid='",
			user_num_id,
			"' and campaignid='",
			campaign_id,
			"';"
		});
		return this.method_15(string_, out out_log);
	}
	public CampaignBean method_15(string string_1, out string string_2)
	{
		CampaignBean result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			this.method_20(out string_2);
			if (this.oleDbCommand_6 == null || this.oleDbCommand_6.Connection == null || this.oleDbCommand_6.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_6 = new OleDbCommand(string_1, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_6.CommandText = string_1;
			}
			OleDbDataReader oleDbDataReader = this.oleDbCommand_6.ExecuteReader();
			if (!oleDbDataReader.Read())
			{
				oleDbDataReader.Close();
				string_2 = "";
				result = null;
			}
			else
			{
				CampaignBean campaignBean = new CampaignBean();
				campaignBean.shop_keeper_id = oleDbDataReader["shopkeeperid"].ToString();
				campaignBean.user_num_id = oleDbDataReader["usernumberid"].ToString();
				campaignBean.campaign_id = oleDbDataReader["campaignid"].ToString();
				oleDbDataReader.Close();
				result = campaignBean;
			}
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			this.method_23();
			result = null;
		}
		return result;
	}
	public bool method_16(string qqgroup, string qqgroupname, QQItem qq_item, out string out_log)
	{
		bool result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			this.method_22(out out_log);
			string text = "INSERT INTO qqgroupmember(qq, qqgroup, qqgroupname) VALUES ('{qq}','{qqgroup}','{qqgroupname}');";
			text = text.Replace("{qq}", qq_item.uin).Replace("{qqgroup}", qqgroup).Replace("{qqgroupname}", qqgroupname.Replace("'", ""));
			if (this.oleDbCommand_7 == null || this.oleDbCommand_7.Connection == null || this.oleDbCommand_7.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_7 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_7.CommandText = text;
			}
			this.oleDbCommand_7.ExecuteNonQuery();
			out_log = "";
			result = true;
		}
		catch (Exception ex)
		{
			out_log = "出错啦！" + ex.ToString();
			this.method_23();
			result = false;
		}
		return result;
	}
	public bool method_17(out string string_1)
	{
		this.method_22(out string_1);
		string string_2 = "delete from qqgroupmember";
		return this.method_7(string_2, out string_1);
	}
	public ArrayList method_18(out string string_1)
	{
		string text = "select qq,count(qqgroup) as ingrpnum from qqgroupmember group by qq order by count(qqgroup) desc;";
		ArrayList result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			this.method_22(out string_1);
			if (this.oleDbCommand_8 == null || this.oleDbCommand_8.Connection == null || this.oleDbCommand_8.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_8 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_8.CommandText = text;
			}
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = this.oleDbCommand_8.ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(new QQItem
				{
					uin = oleDbDataReader["qq"].ToString(),
					ingrpnum = int.Parse(oleDbDataReader["ingrpnum"].ToString())
				});
			}
			oleDbDataReader.Close();
			string_1 = "";
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_1 = "出错啦：" + ex.ToString();
			this.method_23();
			result = null;
		}
		return result;
	}
	public ArrayList method_19(string string_1, out string string_2)
	{
		ArrayList result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			this.method_22(out string_2);
			string text = "select * from qqgroupmember where qq='" + string_1 + "' ";
			if (this.oleDbCommand_8 == null || this.oleDbCommand_8.Connection == null || this.oleDbCommand_8.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_8 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_8.CommandText = text;
			}
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = this.oleDbCommand_8.ExecuteReader();
			while (oleDbDataReader.Read())
			{
				arrayList.Add(new QQqun
				{
					num = oleDbDataReader["qqgroup"].ToString(),
					name = oleDbDataReader["qqgroupname"].ToString()
				});
			}
			oleDbDataReader.Close();
			string_2 = "";
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = "出错啦：" + ex.ToString();
			this.method_23();
			result = null;
		}
		return result;
	}
	public bool create_order(Aliorder aliorder, out string string_1)
	{
		bool result;
		try
		{
			this.method_6(out string_1);
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			string text = "INSERT INTO aliorder(taobaoTradeId, auctionId, auctionTitle, exShopTitle, payStatus, auctionNum,  totalAlipayFeeString, feeString, discountAndSubsidyToString, tbTradeCreateTime, payPubTime, terminalType, promotPosition, alimamaAccount) VALUES ('{taobaoTradeId}', '{auctionId}', '{auctionTitle}', '{exShopTitle}', {payStatus}, {auctionNum}, '{totalAlipayFeeString}', '{feeString}', '{discountAndSubsidyToString}', '{tbTradeCreateTime}', '{payPubTime}', '{terminalType}', '{promotPosition}', '{alimamaAccount}');";
			text = text.Replace("{taobaoTradeId}", aliorder.taobaoTradeId).Replace("{auctionId}", aliorder.num_iid).Replace("{auctionTitle}", aliorder.title.Replace("'", "").Replace("\n", "").Replace("\t", "")).Replace("{exShopTitle}", aliorder.shop_title.Replace("'", "").Replace("\n", "").Replace("\t", "")).Replace("{payStatus}", string.Concat(aliorder.payStatus)).Replace("{auctionNum}", string.Concat(aliorder.auctionNum)).Replace("{totalAlipayFeeString}", aliorder.totalAlipayFeeString).Replace("{feeString}", aliorder.feeString).Replace("{discountAndSubsidyToString}", aliorder.discountAndSubsidyToString).Replace("{tbTradeCreateTime}", aliorder.tbTradeCreateTime).Replace("{payPubTime}", aliorder.payPubTime).Replace("{terminalType}", aliorder.terminalType).Replace("{promotPosition}", aliorder.shop_title).Replace("{alimamaAccount}", aliorder.alimamaAccount);
			if (this.oleDbCommand_0 == null || this.oleDbCommand_0.Connection == null || this.oleDbCommand_0.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_0 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_0.CommandText = text;
			}
			this.oleDbCommand_0.ExecuteNonQuery();
			this.oleDbCommand_0.Dispose();
			string_1 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_1 = ex.ToString();
			result = false;
		}
		return result;
	}
	private void method_20(out string string_1)
	{
		if (!this.method_21("campaign", out string_1))
		{
			string string_2 = "CREATE TABLE campaign (shopkeeperid varchar(30) NOT NULL,usernumberid varchar(30) NOT NULL,campaignid varchar(30) NOT NULL ,  PRIMARY KEY (shopkeeperid,usernumberid,campaignid) ) ";
			this.method_7(string_2, out string_1);
		}
	}
	public bool method_21(string string_1, out string string_2)
	{
		bool result;
		try
		{
			string text = "select count(1) from " + string_1;
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			new ArrayList();
			if (this.oleDbCommand_6 == null || this.oleDbCommand_6.Connection == null || this.oleDbCommand_6.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_6 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_6.CommandText = text;
			}
			this.oleDbCommand_6.ExecuteReader().Close();
			string_2 = "";
			result = true;
		}
		catch
		{
			string_2 = "";
			result = false;
		}
		return result;
	}
	private void method_22(out string string_1)
	{
		if (!this.method_21("qqgroupmember", out string_1))
		{
			string string_2 = "CREATE TABLE qqgroupmember (qq varchar(30) NOT NULL,qqgroup varchar(30) NOT NULL,qqgroupname varchar(100) NOT NULL ,  PRIMARY KEY (qq,qqgroup) ) ";
			this.method_7(string_2, out string_1);
		}
	}
	public void method_23()
	{
		try
		{
			this.oleDbConnection_0.Close();
			this.oleDbConnection_0.Dispose();
			this.oleDbConnection_0 = null;
		}
		catch
		{
			this.oleDbConnection_0 = null;
		}
	}
	public void method_24()
	{
		string text = this.app_path + "\\config\\阿里妈妈订单.mdb";
		if (!File.Exists(text))
		{
			throw new Exception("目标数据库不存在,无法压缩");
		}
		try
		{
			this.oleDbConnection_0.Close();
			this.oleDbConnection_0.Dispose();
			this.oleDbConnection_0 = null;
			string text2 = "aliodr" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak";
			text2 = text.Substring(0, text.LastIndexOf("\\") + 1) + text2;
			string destconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text2 + ";Jet OLEDB:Database Password=ali(*)135";
			string sourceConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + ";Jet OLEDB:Database Password=ali(*)135";
			new JetEngineClass().CompactDatabase(sourceConnection, destconnection);
			File.Copy(text2, text, true);
			File.Delete(text2);
		}
		catch
		{
		}
		finally
		{
			this.set_pay_order_mdb();
		}
	}
	public ArrayList method_3(string string_1, out string string_2)
	{
		ArrayList result;
		try
		{
			this.method_6(out string_2);
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			if (this.oleDbCommand_1 == null || this.oleDbCommand_1.Connection == null || this.oleDbCommand_1.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_1 = new OleDbCommand(string_1, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_1.CommandText = string_1;
			}
			ArrayList arrayList = new ArrayList();
			OleDbDataReader oleDbDataReader = this.oleDbCommand_1.ExecuteReader();
			while (oleDbDataReader.Read())
			{
				PayOrder value = this.method_4(oleDbDataReader);
				arrayList.Add(value);
			}
			string_2 = "";
			oleDbDataReader.Close();
			oleDbDataReader.Dispose();
			result = arrayList;
		}
		catch (Exception ex)
		{
			string_2 = ex.ToString();
			result = null;
		}
		return result;
	}
	private PayOrder method_4(OleDbDataReader oleDbDataReader_0)
	{
		return new PayOrder
		{
			id = int.Parse(oleDbDataReader_0["oid"].ToString()),
			taobaoTradeParentId = oleDbDataReader_0["taobaoTradeId"].ToString(),
			num_iid = oleDbDataReader_0["auctionId"].ToString(),
			title = oleDbDataReader_0["auctionTitle"].ToString(),
			shop_title = oleDbDataReader_0["exShopTitle"].ToString(),
			payStatus = oleDbDataReader_0["payStatus"].ToString(),
			auctionNum = oleDbDataReader_0["auctionNum"].ToString(),
			totalAlipayFeeString = oleDbDataReader_0["totalAlipayFeeString"].ToString(),
			feeString = oleDbDataReader_0["feeString"].ToString(),
			discountAndSubsidyToString = oleDbDataReader_0["discountAndSubsidyToString"].ToString(),
			createTime = oleDbDataReader_0["tbTradeCreateTime"].ToString(),
			earningTime = oleDbDataReader_0["payPubTime"].ToString(),
			terminalType = oleDbDataReader_0["terminalType"].ToString(),
			adzone_name = oleDbDataReader_0["promotPosition"].ToString(),
			alimamaAccount = oleDbDataReader_0["alimamaAccount"].ToString()
		};
	}
	public bool method_5(string string_1, string string_2, out string string_3)
	{
		bool result;
		try
		{
			string text = "select count(" + string_2 + ") from " + string_1;
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			new ArrayList();
			if (this.oleDbCommand_6 == null || this.oleDbCommand_6.Connection == null || this.oleDbCommand_6.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_6 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_6.CommandText = text;
			}
			this.oleDbCommand_6.ExecuteReader().Close();
			string_3 = "";
			result = true;
		}
		catch
		{
			string_3 = "";
			result = false;
		}
		return result;
	}
	private void method_6(out string string_1)
	{
		if (!this.method_5("aliorder", "promotPosition", out string_1))
		{
			string string_2 = "alter table aliorder add COLUMN promotPosition varchar(100) NOT NULL";
			this.method_7(string_2, out string_1);
		}
	}
	public bool method_7(string string_1, out string string_2)
	{
		bool result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			if (this.oleDbCommand_2 == null || this.oleDbCommand_2.Connection == null || this.oleDbCommand_2.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_2 = new OleDbCommand(string_1, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_2.CommandText = string_1;
			}
			this.oleDbCommand_2.ExecuteNonQuery();
			string_2 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_2 = ex.ToString();
			result = false;
		}
		return result;
	}
	public bool method_8(SendTaskItem gclass11_0, out string string_1)
	{
		bool result;
		try
		{
			if (this.oleDbConnection_0 == null)
			{
				this.set_pay_order_mdb();
			}
			string text = "INSERT INTO sendtask(taskdt,taskname) VALUES ({taskdt},'{taskname}');";
			text = text.Replace("{taskdt}", gclass11_0.task_time).Replace("{taskname}", gclass11_0.task_name);
			if (this.oleDbCommand_3 == null || this.oleDbCommand_3.Connection == null || this.oleDbCommand_3.Connection.State != ConnectionState.Open)
			{
				this.oleDbCommand_3 = new OleDbCommand(text, this.oleDbConnection_0);
			}
			else
			{
				this.oleDbCommand_3.CommandText = text;
			}
			this.oleDbCommand_3.ExecuteNonQuery();
			this.oleDbCommand_3.Dispose();
			string_1 = "";
			result = true;
		}
		catch (Exception ex)
		{
			string_1 = ex.ToString();
			result = false;
		}
		return result;
	}
	public bool update_task(SendTaskItem gclass11_0, out string string_1)
	{
		string text = "update sendtask set taskdt={taskdt},taskname='{taskname}' where taskid={taskid}";
		text = text.Replace("{taskdt}", gclass11_0.task_time.Substring(4)).Replace("{taskname}", gclass11_0.task_name).Replace("{taskid}", string.Concat(gclass11_0.task_id));
		return this.method_7(text, out string_1);
	}
}
